<?php

Yii::import('zii.widgets.CPortlet');
Yii::import('application.modules.news.models.NewsCategories');
Yii::import('application.modules.news.models.News');
Yii::import('application.modules.video.models.Video');
Yii::import('application.modules.gallery.models.Gallery');
Yii::import('application.modules.file.models.FileCategories');
Yii::import('application.modules.file.models.File');

class Right extends CPortlet {

    public function getNotice() {
        return NewsCategories::model()->findByAttributes(array('rank' => NewsCategories::RIGHT));
    }

    public function findNews($id) {
        $criteria = new CDbCriteria(array(
            'order' => 'create_time DESC',
        ));
        $criteria->limit = 5;
        $criteria->condition = 'status = 1 and category_id =' . $id;
        $model = News::model()->findAll($criteria);
        return $model;
    }

    public function getVideo() {
        $criteria = new CDbCriteria(array(
            'order' => 'create_time DESC',
        ));
        $criteria->condition = 'status = 1';
        $model = Video::model()->findAll($criteria);
        return $model;
    }

    public function getGallery() {
        $criteria = new CDbCriteria(array(
            'order' => 'create_time DESC',
        ));
        $model = Gallery::model()->findAll($criteria);
        return $model;
    }

    public function getFile() {
        $criteria = new CDbCriteria;
        $criteria->addSearchCondition('rank', FileCategories::RIGHT);
        return FileCategories::model()->findAll($criteria);
    }

    public function getFileItem($id) {
        $criteria = new CDbCriteria(array(
            'order' => 'create_time DESC',
        ));
        $criteria->condition = 'category_id =' . $id;
        $model = File::model()->findAll($criteria);
        return $model;
    }

    public function getAds() {
        $criteria = new CDbCriteria(array(
            'order' => 'create_time DESC',
        ));
        $criteria->condition = 'category_id =' . AdsPartners::ADS;
        $model = AdsPartners::model()->findAll($criteria);
        return $model;
    }

    protected function renderContent() {
        $this->render('right');
    }

}

?>